import request from "@/services/interceptors";
// import { useAsyncEffect } from "ahooks";
// import { useMemo, useState } from "react";

// /**  获取课程列表 */
// export const useGetCourseList = () => {
//   const [courseList, setCourseList] = useState([]);
//   useAsyncEffect(async () => {
//     const res = await request.sgks.courseAllList();
//     setCourseList(
//       res.data?.map((i) => {
//         return {
//           label: i.courseName,
//           value: i.courseId,
//         };
//       })
//     );
//   }, []);

//   const courseOptions = useMemo(() => {
//     return courseList.reduce((pre, cur) => {
//       return {
//         ...pre,
//         [cur.value]: cur.label,
//       };
//     }, {});
//   }, [courseList]);

//   return [courseList, courseOptions];
// };


export const transArrTOurl = (arr: any[]) => {
  if (Array.isArray(arr)) {
    return arr.filter(i => i?.status === "done").map(i => {
      return i.url || i?.response?.data
    }).join(",")
  }
}

export const transUrlTOArr = (str: string) => {
  if (typeof str === "string") {
    return str.split(',').map((i, idx) => {
      const trimmedUrl = i.trim();
      const fileName = trimmedUrl.split('/').pop() || `文件${idx + 1}`;
      return {
        url: i.trim(),
        name: `${fileName}`,
        status: "done",
        uid: `${idx}`,
      }
    })
  }
}

export function replaceKnowledgeDesc(knowledgeDesc: string, parameterValues: { parameterValue: string }[]) {
  return knowledgeDesc.replace(/\$\{(\d+)\}/g, (_, index) => {
    return parameterValues[Number(index)]?.parameterValue ?? "";
  });
}